import { getLoginResultModel, getUserInfoResultModel, LoginParams, LoginResultModel } from './model/userModel'
import { ErrorMessageMode } from '/#/axios'
import { defHttp } from '/@/utils/http/axios'
const Api = {
  Login: '/passport/login',
  logoutApi: '/passport/logout',
  GetUserInfo: '/admin.user/detail',
}

/**
 * 用户登录
 * @param {*} data
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<getLoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    }
  )
}

export function logoutApi() {
  return defHttp.post({ url: Api.logoutApi })
}

/**
 * 获取当前登录的用户信息
 */
export function getUserInfo() {
  return defHttp.get<getUserInfoResultModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' })
}
